const app = getApp();
import services from '../../services/clockin';

Page({
  data: {
    itemsCustom: [{
        title: '外勤审批',
        icon: 'ClockCircleFill',
        sclass: 'yellow',
        count: 'outingCount',
        type: 1
      },
      {
        title: '补卡审批',
        icon: 'ClockCircleFill',
        sclass: 'yellow',
        count: 'additionCount',
        type: 0
      },
      {
        title: '日度报表',
        icon: 'HistogramOutline',
        sclass: 'blue',
        count: '',
        type: 2
      },
      {
        title: '周期报表',
        icon: 'HistogramOutline',
        sclass: 'blue',
        count: '',
        type: 3
      },
      {
        title: '导出报表',
        icon: 'DownlandOutline',
        sclass: 'blue',
        count: '',
        type: 4
      },
    ],
    counts: {
      additionCount: '',
      outingCount: '',
    }
  },
  async onLoad() {
    await this.queryGetApprovePreview();
  },
  handleTapItem(item) {
    switch (item.type) {
      case 0: {
        dd.navigateTo({
          url: `/page/approveMakeUp/approveMakeUp`
        });
        break;
      }
      case 1: {
        dd.navigateTo({
          url: `/page/approveOffSite/approveOffSite`
        });
        break;
      }
      case 2: {
        dd.navigateTo({
          url: `/page/reportDaily/reportDaily`
        });
        break;
      }
      case 3: {
        dd.navigateTo({
          url: `/page/reportWeekly/reportWeekly`
        });
        break;
      }
      case 4: {
        dd.navigateTo({
          url: `/page/reportDownLoad/reportDownLoad`
        });
        break;
      }
    }
  },
  async queryGetApprovePreview() {
    try {
      const {
        unionid
      } = app.globalData.userInfo || {};

      const res = await services.getApprovePreview(unionid || '');
      if (res && res.data) {
        this.setData({
          counts: {
            additionCount: res.data.addition_count || '',
            outingCount: res.data.outing_count || ''
          }
        });
      }
    } catch (error) {
      console.log(error);
    }
  }
});